package com.xiaoniu.forum.web.controller.app;

import com.xiaoniu.forum.common.utils.PageUtils;
import com.xiaoniu.forum.common.utils.R;
import com.xiaoniu.forum.service.TopicSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app/search")
@Api("检索")
public class AppSearchController {
    @Autowired
    private TopicSearchService topicSearchService;

    @ApiOperation("检索话题")
    @GetMapping("/topic/{keyword}/{current}/{size}")
    public R searchTopic(@PathVariable String keyword,
                         @PathVariable Integer size,
                         @PathVariable Integer current){
        if (size>20){ //最大20条记录每页
            size = 20;
        }
        PageUtils page = new PageUtils(current, size);
        topicSearchService.search(keyword,page);
        return R.ok().put("page",page);
    }
}
